$(document).ready(function () {


    var countdown=60;
    function settime(obj) {
        //开始判断倒计时是否为0
        if (countdown == 0) {
            obj.removeAttribute("disabled");
            obj.innerText="免费获取验证码";
            countdown = 60;
            return;
        } else {
            obj.setAttribute("disabled", true);
            obj.innerText="重新发送(" + countdown + ")";
            countdown--;
        }
        setTimeout(function() {settime(obj)},1000)
    }

    $("#sendCode").click(function () {
        var isAlert  =  $("input[name=tips_js_alert]").val() || false;
            console.log($("input[name=tips_js_alert]").val())
        var self = this;
        var seccode_verify = $("input[name=seccode_verify]").val();
        var mobile = $("input[name=mobile]").val();
        var mobilereg = /^[1][3,4,5,6,7,8][0-9]{9}$/;
        if (!mobilereg.test(mobile))
        {
            $("#login_error_msg").css('display','list-item').find('em').text('请输入正确的手机号');
            if(isAlert) alert('请输入正确的手机号');

            return;
        }
        var param = "type=login&mobile="+mobile+"&seccode_verify="+seccode_verify;
        //发送

        $.get(G_BASE_URL + '/account/ajax/send_valid_code/?'+param, function (result) {

            if (result.errno == -1)
            {
                $("#captcha").click();
                $("#login_error_msg").css('display','list-item').find('em').text(result.err);
                if(isAlert) alert(result.err);

            }
            else
            {
                $("#login_error_msg").css('display','none');
                settime(self); //开始倒计时

            }

        }, 'json');

    });

})
